package czy.demo.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpSession;


@RestController
@Api(tags = "会话控制器")
@RequestMapping("session")
public class SessionController {

    @GetMapping("/id")
    @ApiOperation("获取会话ID")
    public String session(
           @ApiIgnore HttpSession session
    ){
        return session.getId();
    }

    @PostMapping()
    public String setUsername(
            @ApiIgnore HttpSession session,
            @ApiParam("属性名") @RequestParam  String name,
            @ApiParam("属性值") @RequestParam  String value
    ){
        session.setAttribute(name,value);
        return "设置成功";
    }

    @GetMapping()
    public String getUsername(
            @ApiIgnore HttpSession session,
            @ApiParam("属性名") @RequestParam  String name
    ){
        return (String)session.getAttribute(name);
    }

}
